package com.luobu.javaee.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.luobu.javaee.domain.Document;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DocumentMapper extends BaseMapper<Document> {

    // 查询文档是否存在
    @Select("select * from document where userId=#{userId} and docName=#{docName} and archiveId=#{archiveId}")
    List<Document> findByUserIdAndDocNameAndArchiveId(Long userId, String docName, Long archiveId);

    @Select("select * from document where archiveId=#{archiveId}")
    List<Document> findByArchiveId(Long archiveId);

    @Delete("delete from document where userId=#{userId} and docName=#{docName}")
    void deleteByDocNameAndUserId(String docName, Long userId);


    @Update("update document set archiveId=#{archiveIdNew} where userId=#{userId} and docName=#{docName} and archiveId=#{archiveId}")
    int updateArchiveIdByUserIdAndDocNameAndArchiveId(Long userId, String docName, Long archiveId, Long archiveIdNew);

    @Update("update document set archiveId=-1 where id=#{docId}")
    int updateArchiveIdBydocId(Long docId);
}
